package com.aos.demo.customer;

import com.aos.demo.Exception.ApiRequestException;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Collections;
import java.util.List;

@RequestMapping(path = "api/v2/customers")
@RestController
public class CustomerControllerV2 {

    private final CustomerService customerService;

    public CustomerControllerV2(CustomerService customerService){
         this.customerService = customerService;
    }

    @GetMapping
    List<Customer> getCustomers(){
        return customerService.getCustomers();
    }


    @GetMapping(path = "{customerId}")
    Customer getCustomer(@PathVariable("customerId") Long Id){
        return customerService.getCustomer(Id);
    }

    @GetMapping(path = "{customerId}/exception")
    Customer getException(@PathVariable("customerId") Long Id){
        throw new ApiRequestException(
                "ApiRequestException for customer" +Id
        );
    }

    @PostMapping
    void createNewCustomer(@Valid @RequestBody Customer customer){
        System.out.println("POST 请求");
        System.out.println(customer);
    }

    @PutMapping
    void updateCustomer(@RequestBody Customer customer){
        System.out.println("UPDATE 请求");
        System.out.println(customer);
    }

    @DeleteMapping(path = "{customerID}")
    void deleteCustomer(@PathVariable("customerID") Long id){
        System.out.println("DELETE 请求，删除 Customer,ID 为" + id);
    }

}
